let beforurl = "http://localhost:8080/api/v1";
function myHeader(url, type, data, callback) {
  let formDataCode = data instanceof FormData;
  $.ajax({
    url: beforurl + url,
    type: type,
    data: data,
    contentType: formDataCode ? false : 'application/x-www-form-urlencoded',
    processData: formDataCode ? false : true,
    headers: {
      Authorization: sessionStorage.getItem('big_news'),
    },
    success: function (resData) {
      if (resData.code == 403) {
        window.parent.location.href = "./login.html"
        return false;
      }
      callback(resData);
    }
  })
}

//原生方法
function myJsGet(url, callback, data = null) {
  let xhr = new XMLHttpRequest();

  let key = [];
  if (data != null) {
    for (let k in data) {
      key.push(k + '=' + data[k])
    }
    key = key.join('&');
    url = beforurl + url + '?' + key;
  } else {
    url = beforurl + url
  }

  xhr.open('get', url);
  xhr.setRequestHeader('Authorization', sessionStorage.getItem('big_news'))
  xhr.send();
  xhr.onload = function () {
    let xhrhtml = JSON.parse(xhr.responseText);
    callback(xhrhtml);
  }
}